﻿Public Partial Class Frm_ReImpresion
    Inherits System.Web.UI.Page
    Public Ruta As String
    Public Archivo As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then

        End If
    End Sub
    Private Sub ObtieneFolios()
        Dim exec As New BusinessCatastrofico.FoliosReimpresion
        Dim rp As New NetResponse.MsSqlServer
        Dim RutContratante As String
        Dim fRut As New FunGenerales
        Dim lRut As Integer
        Dim szDigito As String
        szDigito = ""

        If Not fRut.ValidarRut(txtRutContratante.Text, lRut, szDigito) Then
            txtRutContratante.Text = ""
            txtRutContratante.AutoUpdateAfterCallBack = True
            Exit Sub
        End If

        RutContratante = txtRutContratante.Text.Replace("-", "").Replace(".", "").Trim

        exec._Rut = Mid(RutContratante, 1, Len(RutContratante) - 1)
        exec.Get_Folios(rp)

        cbFolios.DataSource = Nothing

        If rp.TieneDatos Then
            cbFolios.DataSource = rp.Ds.Tables(0)
            cbFolios.DataValueField = "Folio_Salud"
            cbFolios.DataBind()
            cbFolios.AutoUpdateAfterCallBack = True
        Else
            Anthem.Manager.AddScriptForClientSideEval("alert('No hay Propuesta para el Rut');")
            cbFolios.Enabled = False
        End If
        If rp.Errores Then
        End If



        rp.Dispose()
        exec.Dispose()

    End Sub
    Protected Sub btConsultar_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btConsultar.Click
        ObtieneFolios()
    End Sub
    Private Sub Abre_PDF()
        Dim exec As New BusinessCatastrofico.FoliosReimpresion
        Dim rp As New NetResponse.MsSqlServer
        Dim Pdf_Ruta As String = ConfigurationManager.AppSettings("pathPDF")

        'Dim Folio As Integer
        ' Folio = 
        exec._folio = cbFolios.SelectedItem.Text
        exec.Get_Ruta(rp)

        If rp.TieneDatos Then
            Archivo = Pdf_Ruta & rp.Ds.Tables(0).Rows(0).Item(1).ToString
            Ruta = rp.Ds.Tables(0).Rows(0).Item(1).ToString
        End If

        Rp.Dispose()
        exec.Dispose()

          End Sub


    Protected Sub cbFolios_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cbFolios.SelectedIndexChanged

        If cbFolios.SelectedValue = "--- SELECCIONE ---" Then
            Exit Sub
        Else
            Abre_PDF()

            If IO.File.Exists(Archivo) = True Then
                Anthem.Manager.AddScriptForClientSideEval("window.open('PDF/" & Ruta & "','PDF','status=1')")
            Else
                Anthem.Manager.AddScriptForClientSideEval("alert('Pdf NO Disponible, contáctese con Banchile');")
            End If

        End If

        cbFolios.SelectedIndex = -1
        cbFolios.AutoUpdateAfterCallBack = True

    End Sub


    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim szURL As String
        szURL = "frm_DatosSimulacion.aspx"
        Response.Redirect(szURL)
    End Sub
End Class